package com.paranoidvulture.javaEngine.Views;

import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;

import com.paranoidvulture.javaEngine.MainPackage.ScreenManager;


public class EditorMenu extends ViewBase {
	
	public EditorMenu(ScreenManager s){
		super(s);
	}

	//variables
	Menu men;
	String[] menuItems = {
			"Map Editor",
			"Character Editor",
			"Item Editor",
			"Building Editor",
			"Main Menu"
	};
	MapEditor mEd;
	
	
	public void init(){
		views = new ViewHandler();
		this.setEnabled(false);
		men = new Menu(s, menuItems);
		men.init();
		men.setEnabled(false);
		mEd = new MapEditor(s);
		mEd.init();
		views.addToList(men);
	}
	
	public void update(long timePassed){
		if(this.getEnabled()){
			men.setEnabled(true);
		}
		if (men.getSelectedOption()){
			if(men.getSelectedIndex() == 0){
				men.select();
				views.addToList(mEd);
				//views.getNested(mEd.views);
			}
			else if(men.getSelectedIndex() == 1){
				
			}
			else if(men.getSelectedIndex() == 2){
				
			}
			else if(men.getSelectedIndex() == 4){
				//somehow go back
				
			}
		}
		views.updateCurrentView(timePassed);
	}
	
	public void draw(Graphics2D g){
		views.drawCurrentView(g);
	}
	
	@Override
	public void keyPressed(KeyEvent e) {
		int keyCode = e.getKeyCode();
		if (keyCode == KeyEvent.VK_ESCAPE){
			if(views.getNestedLevel() == 2){ 
				views.removeTopView();				
			}else { 
				views.updateKeyEventPressed(e); 
			}
		} else {
			views.updateKeyEventPressed(e);
		}		
	}

	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		views.updateMouseClicked(e);
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		views.updateMouseEntered(e);
	}

	@Override
	public void mouseExited(MouseEvent e) {
		views.updateMouseExited(e);
	}

	@Override
	public void mousePressed(MouseEvent e) {
		views.updateMousePressed(e);
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		views.updateMouseReleased(e);
	}

	@Override
	public void mouseWheelMoved(MouseWheelEvent e) {
		views.updateMouseWheelMoved(e);
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		views.updateMouseDragged(e);
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		views.updateMouseMoved(e);
	}
	
	
}
